home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
program
/
slix0987.zip
/
2HR8.BAS
< prev
next >
Wrap
BASIC Source File
|
1996-08-10
|
28KB
|
747 lines
DEFINT A-Z
'2HR8.BAS
'Written by Lloyd Chang
'This file is part of slix
'The conditions to use
'2HR8 are the same as those
'applied to the use of slix.
COLOR 7
PRINT
PRINT "2HR8 - BMP/GIF to HR8 converter"
PRINT "Written by Lloyd Chang"
PRINT
PRINT "This could take a while... :)"
PRINT
COLOR 23
PRINT "WORKING"
HR8Header$ = "HR8"
HR8HeaderSize% = 7
RGBPaletteFile% = FREEFILE
PaletteRGB$ = SPACE$(768)
DIM RGBPaletteTranslator(255) AS INTEGER
OPEN "RGB.PAL" FOR BINARY AS #RGBPaletteFile%
GET #RGBPaletteFile%, 1, PaletteRGB$
CLOSE #RGBPaletteFile%
FILEXFile% = FREEFILE
filename$ = COMMAND$
'Open file for input so QB stops with an error if it doesn't exist.
OPEN filename$ FOR INPUT AS #FILEXFile%
CLOSE #FILEXFile%
OPEN filename$ FOR BINARY AS #FILEXFile%
FOR Count% = 1 TO LEN(filename$)
SELECT CASE MID$(filename$, Count%, 1)
CASE IS = "."
Outputfile$ = LEFT$(filename$, Count%) + "HR8"
extension% = 1
END SELECT
NEXT Count%
SELECT CASE extension%
CASE IS = 1
CASE ELSE
Outputfile$ = filename$ + ".HR8"
END SELECT
SELECT CASE LOF(FILEXFile%)
CASE IS > 32
HeaderTest$ = SPACE$(32)
CASE ELSE
HeaderTest$ = SPACE$(LOF(FILEXFile%))
END SELECT
GET #FILEXFile%, , HeaderTest$
SELECT CASE LEFT$(HeaderTest$, 2)
CASE IS = "BM"
HeaderSig% = 2
HeaderSig$ = "BMPWIN"
END SELECT
SELECT CASE LEFT$(HeaderTest$, 3)
CASE IS = "GIF"
HeaderSig% = 3
HeaderSig$ = "GIF"
END SELECT
SELECT CASE HeaderSig$
CASE IS = "BMPWIN"
Outputfile% = FREEFILE
OPEN Outputfile$ FOR BINARY AS #Outputfile%
header$ = SPACE$(14)
sizing$ = SPACE$(4)
GET #FILEXFile%, 1, header$
GET #FILEXFile%, 15, sizing$
bmpinfosize = CVI(sizing$)
'bmpinfosize - Is the size of the information header for the bitmap.
' Different bitmap versions have variations in filetypes.
' 40 is a standard windows 3.1 bitmap.
' 12 is for OS/2 bitmaps
'The next routine reads in the appropriate headers and colour tables.
'nbits is the number of bits per pixel - i.e. number of colours
'1 bit = 2 colours, 4 bits = 16 colours, 8 bits = 256 colours, etc.
'the 24 bit mode does not have a palette, its colours are expressed as
'image data
'Design of a windows 3.1 bitmap - Taken from bmp.zip on the
'x2ftp.oulu.fi ftp site under /pub/msdos/programming/formats
'Specifications for a Windows 3.1 bitmap. (.BMP)
'Email any questions/responses to me at zabudsk@ecf.utoronto.ca
'or post to alt.lang.basic or comp.lang.basic.misc.
' | # of |
'Offset | bytes | Function (value)
'-------+--------+--- General Picture information starts here---------
' 0 | 2 | (BM) - Tells us that the picture is in bmp format
' 2 | 4 | Size of the file (without header?)
' 6 | 2 | (0) Reserved1 - Must be zero
' 8 | 2 | (0) Reserved2 - Must be zero
' 10 | 4 | Number of bytes offset of the picture data
'-------+--------+--- Information Header starts here -----------------
' 14 | 4 | (40/12) Size of information header (Win3.1/OS2)
' 18 | 4 | Picture width in pixels
' 22 | 4 | Picture Height in pixels
' 26 | 2 | (1) Number of planes, must be 1
' 28 | 2 | Number of bits per pixel (bpp), must be 1,4,8 or 24
' 30 | 4 | (0) Compression - 0 means no compression, 1,2 are RLEs
' 34 | 4 | Image size in bytes
' 38 | 4 | picture width in pels per metre
' 42 | 4 | picture height in pels per metre
' 46 | 4 | (0) Number of colours used in the picture, 0 means all
' 50 | 4 | (0) Number of important colours, 0 means all
'-------+--------+--- Palette data starts here -----------------------
' 54 | 1 | (b) - blue intensity component, color 0 - range 0 to 255
' 55 | 1 | (g) - green intensity component, color 0 - range 0 to 255
' 56 | 1 | (r) - red intensity component, color 0 - range 0 to 255
' 57 | 1 | (0) - unused
' 58 | 1 | (b) - blue intensity component, color 0 - range 0 to 255
' ... | ... |
' 54 | 4*2^bpp| total range of palette
'-------+--------+--- Image data starts here -------------------------
'54+ | width* | Bitmap data starting at lower left portion of the
'(4*2^n)| height*| image moving from left towards right. Moving up 1
' | (8/bpp)| pixel when at the right hand side of the image, starting
' | | from the left side again, until the top right of the
' | | image is reached
'Note that this format is slightly different for a OS/2 Bitmap.
'The header is the same up to (but not including) bit 30-
'The palette colour values follow at bit 30, with the form...
'1 byte blue intensity
'1 byte green intensity
'1 byte red intensity
'For each colour of the picture.
'Bitmapped image data follows the colour tables
'Special note: When storing 1 bit (2 colour) pictures.
'8 horizontal pixels are packed into 1 byte. Each bit determines
'the colour of one pixel (colour 0 or colour 1)
'4 bit pictures (16 colours) use 2 nibbles (4 bits) for each pixel
'thus there are 2 pixels for each byte of image data.
'8 bit pictures use 1 byte per pixel. Each byte of image data
'represents one of 256 colours.
'24 bit pictures express colour values by using 3 bytes and each has a
'value between 0 and 255. The first byte is for red, the second is for
'green and the third is for blue. Thus (256)^3 or 2^24 of 16777216 different
'colours.
IF bmpinfosize = 12 THEN
infoheader$ = SPACE$(12)
GET #FILEXFile%, 15, infoheader$
nbits = CVI(MID$(infoheader$, 15, 4))
IF nbits = 1 THEN
palet$ = SPACE$(6)
GET #FILEXFile%, bmpinfosize + 15, palet$
ELSEIF nbits = 4 THEN
palet$ = SPACE$(48)
GET #FILEXFile%, bmpinfosize + 15, palet$
ELSEIF nbits = 8 THEN
palet$ = SPACE$(768)
GET #FILEXFile%, bmpinfosize + 15, palet$
END IF
ELSEIF bmpinfosize = 40 THEN
infoheader$ = SPACE$(40)
GET #FILEXFile%, 15, infoheader$
nbits = CVI(MID$(infoheader$, 15, 4))
IF nbits = 1 THEN
palet$ = SPACE$(8)
GET #FILEXFile%, bmpinfosize + 15, palet$
ELSEIF nbits = 4 THEN
palet$ = SPACE$(64)
GET #FILEXFile%, bmpinfosize + 15, palet$
ELSEIF nbits = 8 THEN
palet$ = SPACE$(1024)
GET #FILEXFile%, bmpinfosize + 15, palet$
END IF
END IF
ft$ = MID$(header$, 1, 2)
'PRINT "Type of file (Should be BM): "; ft$
filesize& = CVL(MID$(header$, 3, 4))
'PRINT "Size of file: "; filesize&
r1 = CVI(MID$(header$, 7, 2))
'PRINT "Reserved 1: "; r1
r2 = CVI(MID$(header$, 9, 2))
'PRINT "Reserved 2: "; r2
offset = CVL(MID$(header$, 11, 4))
'PRINT "Number of bytes offset from beginning: "; offset
'PRINT
headersize = CVL(MID$(infoheader$, 1, 4))
'PRINT "Size of header: "; headersize
PicWidth = CVL(MID$(infoheader$, 5, 4))
'PRINT "Width: "; picwidth
PicHeight = CVL(MID$(infoheader$, 9, 4))
'PRINT "Height: "; picheight
HeaderXSize1$ = CHR$(PicWidth \ 256)
HeaderXSize2$ = CHR$(PicWidth MOD 256)
HeaderYSize1$ = CHR$(PicHeight \ 256)
HeaderYSize2$ = CHR$(PicHeight MOD 256)
PUT #Outputfile%, 1, HR8Header$
PUT #Outputfile%, , HeaderXSize1$
PUT #Outputfile%, , HeaderXSize2$
PUT #Outputfile%, , HeaderYSize1$
PUT #Outputfile%, , HeaderYSize2$
FileNoHeaderCount& = 0
nplanes = CVI(MID$(infoheader$, 13, 4))
'PRINT "Planes: "; nplanes
'PRINT "Bits per plane: "; nbits
'PRINT
IF headersize = 40 THEN
'PRINT "Compression: ";
comptype = CVL(